import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

const store = new Vuex.Store({
	state: {
		musicIDs: [],
		nextID: '',
		previousID: ''
	},
	mutations: {
		INIT_MUSICIDS(state, payload) {
			state.musicIDs = payload;
		},
		NEXT_MUSICID(state, payload) {
			for (let i = 0; i < state.musicIDs.length; i++) {
				if (state.musicIDs[i] == payload) {
					state.nextID = state.musicIDs[i + 1];
				}
			}
		},
		PREVIOUS_MUSICID(state, payload) {
			for (let i = 1; i < state.musicIDs.length; i++) {
				if (state.musicIDs[i] == payload) {
					state.previousID = state.musicIDs[i - 1];
				}
			}
		}
	}
});

export default store;